package model;

import jade.util.leap.Serializable;

public class Coordenada implements Serializable{
	
	private double lat;
	private double lon;
	private final double R = 6372800; // Raio da terra em metros
	
	public Coordenada(){}
	
	public Coordenada(double lat, double lon){
		this.lat = lat;
		this.lon = lon;
	}
	
	
	public double getLat() {
		return lat;
	}
	public void setLat(double lat) {
		this.lat = lat;
	}
	public double getLon() {
		return lon;
	}
	public void setLon(double lon) {
		this.lon = lon;
	}
	
	public double calculaDistancia(double latitude, double longitude) {
		//private final double R = 6372800; // Raio da terra em metros
        double dLat = Math.toRadians(latitude - lat);
        double dLon = Math.toRadians(longitude - lon);
        double lat = Math.toRadians(this.lat);
        latitude = Math.toRadians(latitude);
 
        double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat) * Math.cos(latitude);
        double c = 2 * Math.asin(Math.sqrt(a));
        return R * c;
    }
	
	
}
